using System.Data;
using ctsu.Data;
using Syncfusion.Windows.Forms.Grid;

namespace ctsu.Admin.Forms.CoreLab
{
	public class ShowLocationContentsDlg : System.Windows.Forms.Form
	{
		private string _location;

		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.TextBox txtLocation;
		private Syncfusion.Windows.Forms.Grid.GridDataBoundGrid dg;

		private System.ComponentModel.Container components = null;

		public ShowLocationContentsDlg(string location)
		{
			this._location = location;
			InitializeComponent();
			InitializeGrid();
			txtLocation.Text = location;
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.txtLocation = new System.Windows.Forms.TextBox();
			this.btnClose = new System.Windows.Forms.Button();
			this.dg = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid();
			((System.ComponentModel.ISupportInitialize)(this.dg)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(112, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Contents of location:";
			// 
			// txtLocation
			// 
			this.txtLocation.Location = new System.Drawing.Point(120, 8);
			this.txtLocation.Name = "txtLocation";
			this.txtLocation.Size = new System.Drawing.Size(160, 20);
			this.txtLocation.TabIndex = 1;
			this.txtLocation.Text = "";
			// 
			// btnClose
			// 
			this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnClose.Location = new System.Drawing.Point(336, 360);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 3;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// dg
			// 
			this.dg.AllowDragSelectedCols = true;
			this.dg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
				| System.Windows.Forms.AnchorStyles.Left)
				| System.Windows.Forms.AnchorStyles.Right)));
			this.dg.Location = new System.Drawing.Point(8, 40);
			this.dg.Name = "dg";
			this.dg.OptimizeInsertRemoveCells = true;
			this.dg.ShowCurrentCellBorderBehavior = Syncfusion.Windows.Forms.Grid.GridShowCurrentCellBorder.GrayWhenLostFocus;
			this.dg.Size = new System.Drawing.Size(712, 312);
			this.dg.SmartSizeBox = false;
			this.dg.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.DoubleClick;
			this.dg.TabIndex = 4;
			this.dg.Text = "gridDataBoundGrid1";
			this.dg.UseListChangedEvent = true;
			// 
			// ShowLocationContentsDlg
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(728, 390);
			this.Controls.Add(this.dg);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.txtLocation);
			this.Controls.Add(this.label1);
			this.Name = "ShowLocationContentsDlg";
			this.Text = "ShowLocationContentsDlg";
			this.Load += new System.EventHandler(this.ShowLocationContentsDlg_Load);
			((System.ComponentModel.ISupportInitialize)(this.dg)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();

		}

		private void InitializeGrid()
		{
			string sql = "SELECT t.ID, t.DrawSample AS DrawID, t.BatchInNum AS Batch, " +
				"d.VisitDate, d.Visit, d.VisitTime, st.Display AS Sample, pt.MRN, " +
				"pt.OtherPatientID, pt.LastName + N',' + pt.FirstName AS PatientName, " +
				"p.ProtocolNumber, tt.Display AS Test, t.Note " +
				"FROM TestSamples t INNER JOIN " +
				"DrawSamples d ON t.DrawSample = d.ID INNER JOIN " +
				"Patient pt ON d.Patient = pt.ID INNER JOIN " +
				"Protocol p ON d.Protocol = p.ID INNER JOIN " +
				"TestType_L tt ON t.TestType = tt.ID INNER JOIN " +
				"SampleType_L st ON d.SampleType = st.ID " +
				"WHERE t.Location = '" + _location + "' ORDER BY t.ID";

			//SqlConnection conn = LoginForm.GetSqlConnection();
			DataTable dt = null;

			try
			{
				DataSet ds = DataAccess.GetDataSet(sql);
				dt = ds.Tables[0];
				dg.DataSource = dt;
				dg.SortBehavior = GridSortBehavior.SingleClick;
			}
			catch
			{
				throw;
			}
			finally
			{
				//if(conn != null)
				//    conn.Dispose();				
			}

		}

		private void ShowLocationContentsDlg_Load(object sender, System.EventArgs e)
		{

		}
	}
}
